import 'package:blibli/components/top-header.dart';
import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  TabController _tabController;
  final List<Tab> _tabs = [
    Tab(text: '歌曲'),
    Tab(text: '推荐'),
    Tab(text: '歌手'),
    Tab(text: '小视频'),
    Tab(text: '文章'),
    Tab(text: '视频'),
    Tab(text: '视频'),
    Tab(text: '视频'),
  ];
  final List<Widget> _tabs_content = [
    Text('1112222'),
    Text('1112222'),
    Text('1112222'),
    Text('1112222'),
    Text('1112222'),
    Text('1112222'),
    Text('1112222'),
    Text('1112222')
  ];
  @override
  void initState() {
    super.initState();
    _tabController =
        TabController(length: _tabs.length, vsync: this, initialIndex: 1);

    // 监听切换
    _tabController.addListener(() {
      print(_tabController.index);
    });
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Scaffold(
        appBar: AppBar(
          title: TopHeader(),
          bottom: TabBar(
            isScrollable: true,
            tabs: _tabs,
            controller: _tabController,
          ),
        ),
        body: TabBarView(
          children: _tabs_content,
          controller: _tabController,
        ),
      ),
    );
  }
}
